package com.object.oriented.exam.system1.controller;

import com.object.oriented.exam.system1.entity.Problem;
import com.object.oriented.exam.system1.entity.Result;
import com.object.oriented.exam.system1.entity.Search;
import com.object.oriented.exam.system1.service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @author : Apple
 * @description :
 * @date : 2023-06-14 09:05
 **/

@RestController
@RequestMapping("/problem")
public class ProblemController {

    @Autowired
    private ProblemService problemService;

    @PostMapping("/search")
    public Result search(@RequestBody Search search) {
        return Result.success(problemService.getProblem(search));
    }

    @PutMapping("/do")
    public Result add(@RequestBody Problem problem) {
        problemService.addProblem(problem);
        return Result.success();
    }

    @PostMapping("/do")
    public Result update(@RequestBody Problem problem) {
        problemService.updateProblem(problem);
        return Result.success();
    }

    @DeleteMapping("/do")
    public Result delete(@RequestBody Problem problem) {
        problemService.removeById(problem.getId());
        return Result.success();
    }
    @GetMapping("/id")
    public Result getById(Long id){
        return Result.success(problemService.getProblemById(id));
    }
}
